home *** CD-ROM | disk | FTP | other *** search
-
- unit RFEdit;
- {Implementation of a TEdit component with
- filter and required field validation }
- {Copyright (c), 1995 by Wm. Romano. All Rights Reserved}
- {Change Log :
- May 10, 1995- Added Beep on Invalid property to allow control
- of informing user when keying an invalid character. Jim Bandy}
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls;
-
- type
- TValidChar = String;
- TRFilterEdit = class(TEdit)
- private
- { Private declarations }
- protected
- FRequired : Boolean;
- FBeepInvalid : Boolean;
- FValidch : TValidChar;
- ValidChar : set of char;
- { Protected declarations }
- Procedure SetValidCh(Value:TValidChar);
- Procedure SetRequired(Value:Boolean);
- Procedure SetBeepInvalid(Value:Boolean);
- public
- { Public declarations }
- Constructor Create(AOwner:TComponent); override;
- procedure KeyPress(var Key: Char); override;
- Procedure DoExit; override;
- published
- { Published declarations }
- Property ValidChars:TValidChar read FValidCh
- Write SetValidCh;
- Property RequiredField:Boolean read FRequired
- write SetRequired;
- Property BeepOnInvalid:Boolean read FBeepInvalid
- write SetBeepInvalid;
- end;
-
- procedure Register;
-
- implementation
-
- Constructor TRFilterEdit.Create(AOwner:TComponent);
- begin
- inherited Create(AOwner);
- FValidCh:='[]';
- FRequired:=False;
- FBeepInvalid := False;
- end;
-
- Procedure TRFilterEdit.SetRequired(Value:Boolean);
- Begin
- if Value<>FRequired then
- FRequired:=Value;
- end;
-
- Procedure TRFilterEdit.SetBeepInvalid(Value:Boolean);
- Begin
- if Value<>FBeepInvalid then
- FBeepInvalid := Value;
- end;
-
- procedure TRFilterEdit.DoExit;
- begin
- inherited DoExit;
- if FRequired then
- begin
- if Text = '' then
- Begin
- MessageDlg(' This field is required! ',mtWarning, [mbOK],0);
- SetFocus;
- end;
- end;
- end ;
-
- Procedure TRFilterEdit.SetValidCh(Value:TValidChar);
- var
- vc3 : set of char;
- x : integer;
- ch1,ch2,ch3 : char;
- SetRange : boolean;
- {Internal Procedure}
- Procedure MakeSet;
- Begin
- if SetRange then vc3:=[ch1..ch2]
- else
- vc3:=[ch1];
- validchar:=validchar+vc3;
- ch1:=#0;ch2:=#0;ch3:=#0;
- SetRange:=False;
- End;
-
- Begin {SetValidCh}
- SetRange:=False;
- if Value<>FValidCh then
- BEGIN
- FValidCh:=Value;
- if (FValidCh[1]='[') and
- (FValidCh[length(FValidCh)]=']' )then
- For x:=2 to length(FValidCh) do
- begin
- ch3:=FValidCh[x];
- if (ch3=',') or (ch3=']') then
- begin
- MakeSet;
- end;
- if ch3='.' then SetRange:=True;
- if ch3='''' then
- begin
- ch3:=FValidCh[x+1];
- x:=x+2;
- end;
- if (SetRange=False) then ch1:=ch3
- else ch2:=ch3;
- end
- else
- FValidCh:='Invalid Format '+ FValidCh;
- end;
- end;
-
- procedure TRFilterEdit.KeyPress(Var Key: Char);
- begin
- if ValidChar <>[] then
- if (NOT (Key in ValidChar)) and (Key<>#08) then
- begin
- if FBeepInvalid then messagebeep(0);
- Key:=#0;
- end;
- inherited KeyPress(Key);
- end;
-
- procedure Register;
- begin
- RegisterComponents('Samples', [TRFilterEdit]);
- end;
-
- end.
-